#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using Agresso.Interface.Layer.Service;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class DADeskAgentForm : Form, ISupplierMappingForm
    {
        DaDeskAgent m_agent;
        DADesk_PDA_Service m_daDeskService;
        UserControlDaDeskAgentMapping m_parent;

        public DADeskAgentForm(DaDeskAgent agent, UserControlDaDeskAgentMapping parent)
        {
            InitializeComponent();
            Text = "Update Agent";
            m_daDeskService = new DADesk_PDA_Service();
            m_parent = parent;
            m_agent = agent;
            textBoxVessel.Text = m_agent.Agent_Name;
            textBoxAgrVesselCode.Text = m_agent.AgrAgent_Code;
            textBoxAgrVesselName.Text = m_agent.AgrAgent_Name;
            textBoxAgrCCCode.Text = m_agent.AgrClient;
        }

        private void button1OK_Click(object sender, EventArgs e)
        {
            updateAgent();
            this.Close();
        }

        private void updateAgent()
        {
            m_agent.AgrAgent_Code = textBoxAgrVesselCode.Text;
            m_agent.AgrAgent_Name = textBoxAgrVesselName.Text;
            m_agent.AgrClient = textBoxAgrCCCode.Text;
            m_daDeskService.UpdateAgent(m_agent);
            m_parent.UpdateSelectedItem(m_agent);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonApply_Click(object sender, EventArgs e)
        {
            updateAgent();
            buttonApply.Enabled = false;
        }

        private void DADeskVesselForm_Load(object sender, EventArgs e)
        {
            textBoxAgrVesselCode.Focus();
        }

        private void activate_apply(object sender, KeyPressEventArgs e)
        {
            buttonApply.Enabled = true;
        }

        private void buttonFindSupplier_Click(object sender, EventArgs e)
        {
            FindSupplierForm form = new FindSupplierForm(this);
            form.ShowDialog();
        }

        public void UpdateAgressoSupplier(asuheader asuheader)
        {
            textBoxAgrVesselCode.Text = asuheader.apar_id;
            textBoxAgrVesselName.Text = asuheader.apar_name;
            textBoxAgrCCCode.Text = asuheader.client;
        }

        public string GetCompanyName()
        {
            return textBoxAgrVesselName.Text;
        }
    }
}